﻿namespace SD.Business
{
    using System.Collections.Generic;
    using System.Linq;
    using SD.DataAccess;

    /// <summary>
    /// Organisation Business Object
    /// </summary>
    public sealed class OrganizationBO
    {
        /// <summary>
        /// Organisation Data Access object
        /// </summary>
        private static OrganizationDao Dao = new OrganizationDao();
        
        /// <summary>
        /// Initializes a new instance of the <see cref="OrganizationBO"/> class.
        /// </summary>
        private OrganizationBO() { }

        /// <summary>
        /// Determines whether [is name exists] [the specified name].
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns>
        /// <c>true</c> if [is name exists] [the specified name]; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsNameExists(string name)
        {
            return Dao.IsNameExists(name);
        }

        /// <summary>
        /// Gets the organization program by organisaton id.
        /// </summary>
        /// <param name="organizationId">The organization id.</param>
        /// <returns></returns>
        public static IQueryable<OrganizationProgram> GetOrganizationProgramByOrganizationId(int organizationId)
        {
            return Dao.GetOrganizationProgramByOrganizationId(organizationId);
        }

        /// <summary>
        /// Adds the organization program.
        /// </summary>
        /// <param name="list">The organization programs.</param>
        /// <returns>true/false result</returns>
        public static bool AddOrganizationProgram(IEnumerable<OrganizationProgram> list)
        {
            return Dao.AddOrganizationProgram(list);
        }

        /// <summary>
        /// Edits the organization progarm.
        /// </summary>
        /// <param name="organizationId">The organization id.</param>
        /// <param name="list">The list.</param>
        /// <returns>true/false result</returns>
        public static bool EditOrganizationProgram(int organizationId, ICollection<OrganizationProgram> list)
        {
            return Dao.EditOrganizationProgram(organizationId, list);
        }

        /// <summary>
        /// Gets the organization ref by category id.
        /// </summary>
        /// <param name="categoryId">The category id.</param>
        /// <returns>collection of Organisation Ref.</returns>
        public static ICollection<OrganizationReference> GetReferencesByCategoryId(int categoryId)
        {
            return Dao.GetReferencesByCategoryId(categoryId).ToList();
        }

        /// <summary>
        /// Adds the organization.
        /// </summary>
        /// <param name="organization">The organization.</param>
        /// <returns>true/false result</returns>
        public static bool AddOrganization(Organization organization)
        {
            return Dao.AddOrganization(organization);
        }

        /// <summary>
        /// Edits the organization.
        /// </summary>
        /// <param name="organization">The organization.</param>
        /// <returns>true/false result</returns>
        public static bool EditOrganization(Organization organization)
        {
            return Dao.EditOrganization(organization);
        }

        /// <summary>
        /// Sets the active organization.
        /// </summary>
        /// <param name="organizationId">The organization id.</param>
        /// <param name="status">if set to <c>true</c> [status].</param>
        /// <returns></returns>
        public static bool SetOrganizationStatus(int organizationId, bool status)
        {
            return Dao.SetActiveOrganization(organizationId, status);
        }

        /// <summary>
        /// Gets the organization.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns>Organisation object</returns>
        public static Organization GetOrganizationById(int id)
        {
            return Dao.GetOrganizationById(id);
        }
    }
}